<template>
  <div>
    <!-- 面包屑导航区 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>驾校信息</el-breadcrumb-item>
      <el-breadcrumb-item>申请管理</el-breadcrumb-item>
    </el-breadcrumb>

    <el-card>
      <!-- 考试列表区域 -->
      <el-table :data="applyList" border stripe>
        <el-table-column type="index"></el-table-column>
        <el-table-column label="学员id" prop="studentId" v-if="false"></el-table-column>
        <el-table-column label="用户名" prop="username" width="164px"></el-table-column>
        <el-table-column label="姓名" prop="name" width="164px"></el-table-column>
        <el-table-column label="套餐id" prop="applyId" width="164px" v-if="false"></el-table-column>
        <el-table-column label="套餐名称" prop="applyName" width="164px"></el-table-column>

        <el-table-column label="操作" width="250px">
          <template slot-scope="scope">
            <!-- 通过申请 -->
            <el-button type="primary" icon="el-icon-success" size="mini"
                       @click="passApply(scope.row)">通过申请
            </el-button>
            <!-- 拒绝申请 -->
            <el-button type="primary" icon="el-icon-error" size="mini"
                       @click="noPassApply(scope.row)">拒绝申请
            </el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
  </div>
</template>

<script>
export default {
  name: "ApplyList",
  data() {
    return {
      applyList: []
    }
  },
  created() {
    this.getApplyList()
  },
  methods: {
    getApplyList() {
      this.$http.get('/driver/studentApply/apply/list').then(res => {
        if (res.data.code === 200) {
          this.applyList = res.data.data
        } else {
          this.$message.error(res.data.message)
        }
      }).catch(err => {
        console.log(err)
        this.$message.error(err.message)
      })
    },
    passApply(data){
      let studentApply = {
        studentId: data.studentId,
        applyId: data.applyId
      }
      this.$http.post('/driver/studentApply/pass/apply', studentApply).then(res => {
        if (res.data.code === 200) {
          this.$message.success(res.data.message)
          this.getApplyList()
        } else {
          this.$message.error(res.data.message)
        }
      }).catch(err => {
        console.log(err)
        this.$message.error(err.message)
      })
    },
    noPassApply(data){
      let studentApply = {
        studentId: data.studentId,
        applyId: data.applyId
      }
      this.$http.post('/driver/studentApply/noPass/apply', studentApply).then(res => {
        if (res.data.code === 200) {
          this.$message.success(res.data.message)
          this.getApplyList()
        } else {
          this.$message.error(res.data.message)
        }
      }).catch(err => {
        console.log(err)
        this.$message.error(err.message)
      })
    }

  }
}
</script>

<style scoped>

</style>
